package ui.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.fy.fyzf.R;
import com.fy.fyzf.base.BaseActivity;
import com.fy.fyzf.bean.AddLookBean;
import com.fy.fyzf.bean.AddNoteBean;
import com.fy.fyzf.bean.DaiKanListBean;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.presenter.DaiKanPresenter;
import com.fy.fyzf.utils.AppUtils;
import com.fy.fyzf.utils.DensityUtil;
import com.fy.fyzf.view.DaiKanCallBack;
import com.fy.fyzf.weight.PinnedHeaderListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import ui.adapter.DaiKanAdapter;
import ui.adapter.DaiKanAdapter1;

//带看
public class WithGlassesHousingActivity extends BaseActivity<DaiKanPresenter> implements DaiKanCallBack {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.rightImage)
    ImageView rightImage;
    //    @BindView(R.id.recycleView)
//    MyRecyclerView recyclerView;
    @BindView(R.id.listView)
    PinnedHeaderListView listView;
    @BindView(R.id.linear)
    LinearLayout linear;
    private int customersId;
    private AddLookBean addLookBean = new AddLookBean();
    private List<DaiKanListBean.HousingFollowsBean> housingFollows;
    private DaiKanAdapter daiKanAdapter;
    private DaiKanAdapter1 daiKanAdapter1;

    @Override
    protected DaiKanPresenter createPresenter() {
        return new DaiKanPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_with_glasses_housing;
    }

    @Override
    public void initView() {
        super.initView();
        setTitleName("带看");
        rightImage.setVisibility(View.VISIBLE);
        rightImage.setBackgroundResource(R.mipmap.add_sign);

        daiKanAdapter1 = new DaiKanAdapter1(this);
    }


    @Override
    public void initData() {
        super.initData();
        customersId = getIntent().getIntExtra("customersId", 0);
        mPresenter.getLookList(customersId);
    }

    @OnClick({R.id.back, R.id.rightImage})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                break;
            case R.id.rightImage:
                Intent intent = new Intent(this, HousingCollectActivity.class);
                intent.putExtra("type", 3);
                intent.putExtra("id", customersId);
                startActivityForResult(intent, 10002);
                break;
        }
    }


    public void addHousingNote(Integer id, String content) {
        AddNoteBean addNoteBean = new AddNoteBean();
        addNoteBean.setHousingId(id);
        addNoteBean.setFollowRemark(content);
        addNoteBean.setFollowType(2);
        mPresenter.addHousingNote(addNoteBean);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 10002) {
            List<Integer> data1 = data.getIntegerArrayListExtra("data");
            if (data1.size() > 0) {
                addLookBean.setCustomerId(customersId);
                addLookBean.setHousingId(data1);
                mPresenter.AddLook(addLookBean);
            }
        }
    }

    @Override
    public void AddLookSuccess(BaseData addLookBean) {
        mPresenter.getLookList(customersId);
    }

    List<DaiKanListBean> headList = new ArrayList<>();
    List<DaiKanListBean.HousingFollowsBean> local = new ArrayList<>();

    @Override
    public void getLookListSuccess(List<DaiKanListBean> listBeans) {
        View view = null;
        if (listBeans.size() == 0 || null == listBeans) {
            listView.setVisibility(View.GONE);
             view = LayoutInflater.from(this).inflate(R.layout.layout_nodata_collection, null);
            linear.addView(view);
        } else {
            listView.setVisibility(View.VISIBLE);
        }
        daiKanAdapter1.setData(listBeans);
        for (int i = 0; i < listBeans.size(); i++) {
            for (int j = 0; j < 1; j++) {
                DaiKanListBean.HousingFollowsBean housingFollowsBean = new DaiKanListBean.HousingFollowsBean(" ", " ", "");
                listBeans.get(i).getHousingFollows().add(0, housingFollowsBean);
            }
        }
        listView.setAdapter(daiKanAdapter1);
        daiKanAdapter1.setData(listBeans);
        /* if (listBeans.size() == 0 || null == listBeans) {
            View view = LayoutInflater.from(this).inflate(R.layout.layout_nodata_collection, null);
            daiKanAdapter.setEmptyView(view);
        }*/
       /*
        for (int i = 0; i < listBeans.size(); i++) {
            headList.add(listBeans.get(i));
            if (listBeans.size() == 0) {
                for (int j = 0; j < listBeans.size(); j++) {
                    local.add(listBeans.get(i).getHousingFollows().get(j));
                }
            }
        }*/
    }

    @Override
    public void addHousingNoteSuccess(BaseData baseData) {
        initData();
    }

}